<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="robots" content="noodp" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
        <title>Docker容器可视化和主机可视化监控 - 豆是不吃豆豉</title><meta name="Description" content="Docker容器可视化和主机可视化监控"><meta property="og:title" content="Docker容器可视化和主机可视化监控" />
<meta property="og:description" content="Docker容器可视化和主机可视化监控" />
<meta property="og:type" content="article" />
<meta property="og:url" content="https://dou-chi.gitee.io/docker-monitor/" />
<meta property="og:image" content="https://dou-chi.gitee.io/logo.png"/>
<meta property="article:published_time" content="2021-01-17T00:28:37+08:00" />
<meta property="article:modified_time" content="2021-01-17T00:28:37+08:00" />
<meta name="twitter:card" content="summary_large_image"/>
<meta name="twitter:image" content="https://dou-chi.gitee.io/logo.png"/>

<meta name="twitter:title" content="Docker容器可视化和主机可视化监控"/>
<meta name="twitter:description" content="Docker容器可视化和主机可视化监控"/>
<meta name="application-name" content="豆是不吃豆豉">
<meta name="apple-mobile-web-app-title" content="豆是不吃豆豉"><meta name="theme-color" content="#ffffff"><meta name="msapplication-TileColor" content="#da532c"><link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
        <link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
        <link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png"><link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png"><link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5"><link rel="manifest" href="/site.webmanifest"><link rel="canonical" href="https://dou-chi.gitee.io/docker-monitor/" /><link rel="prev" href="https://dou-chi.gitee.io/jenkins-auto-test/" /><link rel="next" href="https://dou-chi.gitee.io/act-img-fix/" /><link rel="stylesheet" href="/lib/normalize/normalize.min.css"><link rel="stylesheet" href="/css/style.min.css"><link rel="stylesheet" href="/lib/fontawesome-free/all.min.css"><link rel="stylesheet" href="/lib/animate/animate.min.css"><script type="application/ld+json">
    {
        "@context": "http://schema.org",
        "@type": "BlogPosting",
        "headline": "Docker容器可视化和主机可视化监控",
        "inLanguage": "zh-CN",
        "mainEntityOfPage": {
            "@type": "WebPage",
            "@id": "https:\/\/dou-chi.gitee.io\/docker-monitor\/"
        },"genre": "posts","keywords": "docker, cAdvisor, Grafana, Prometheus, node_exporter","wordcount":  1731 ,
        "url": "https:\/\/dou-chi.gitee.io\/docker-monitor\/","datePublished": "2021-01-17T00:28:37+08:00","dateModified": "2021-01-17T00:28:37+08:00","publisher": {
            "@type": "Organization",
            "name": ""},"author": {
                "@type": "Person",
                "name": "豆是不吃豆豉"
            },"description": "Docker容器可视化和主机可视化监控"
    }
    </script></head>
    <body header-desktop="fixed" header-mobile="auto"><script type="text/javascript">(window.localStorage && localStorage.getItem('theme') ? localStorage.getItem('theme') === 'dark' : ('dark' === 'auto' ? window.matchMedia('(prefers-color-scheme: dark)').matches : 'dark' === 'dark')) && document.body.setAttribute('theme', 'dark');</script>

        <div id="mask"></div><div class="wrapper"><header class="desktop" id="header-desktop">
    <div class="header-wrapper">
        <div class="header-title">
            <a href="/" title="豆是不吃豆豉">豆是不吃豆豉</a>
        </div>
        <div class="menu">
            <div class="menu-inner"><a class="menu-item" href="/posts/"> 所有文章 </a><a class="menu-item" href="/tags/"> 标签 </a><a class="menu-item" href="/categories/"> 分类 </a><a class="menu-item" href="https://github.com/dou-chi" rel="noopener noreffer" target="_blank"> github </a><a class="menu-item" href="https://gitee.com/dou-chi" rel="noopener noreffer" target="_blank"> gitee </a><span class="menu-item delimiter"></span><span class="menu-item search" id="search-desktop">
                        <input type="text" placeholder="搜索文章标题或内容..." id="search-input-desktop">
                        <a href="javascript:void(0);" class="search-button search-toggle" id="search-toggle-desktop" title="搜索">
                            <i class="fas fa-search fa-fw"></i>
                        </a>
                        <a href="javascript:void(0);" class="search-button search-clear" id="search-clear-desktop" title="清空">
                            <i class="fas fa-times-circle fa-fw"></i>
                        </a>
                        <span class="search-button search-loading" id="search-loading-desktop">
                            <i class="fas fa-spinner fa-fw fa-spin"></i>
                        </span>
                    </span><a href="javascript:void(0);" class="menu-item theme-switch" title="切换主题">
                    <i class="fas fa-adjust fa-fw"></i>
                </a>
            </div>
        </div>
    </div>
</header><header class="mobile" id="header-mobile">
    <div class="header-container">
        <div class="header-wrapper">
            <div class="header-title">
                <a href="/" title="豆是不吃豆豉">豆是不吃豆豉</a>
            </div>
            <div class="menu-toggle" id="menu-toggle-mobile">
                <span></span><span></span><span></span>
            </div>
        </div>
        <div class="menu" id="menu-mobile"><div class="search-wrapper">
                    <div class="search mobile" id="search-mobile">
                        <input type="text" placeholder="搜索文章标题或内容..." id="search-input-mobile">
                        <a href="javascript:void(0);" class="search-button search-toggle" id="search-toggle-mobile" title="搜索">
                            <i class="fas fa-search fa-fw"></i>
                        </a>
                        <a href="javascript:void(0);" class="search-button search-clear" id="search-clear-mobile" title="清空">
                            <i class="fas fa-times-circle fa-fw"></i>
                        </a>
                        <span class="search-button search-loading" id="search-loading-mobile">
                            <i class="fas fa-spinner fa-fw fa-spin"></i>
                        </span>
                    </div>
                    <a href="javascript:void(0);" class="search-cancel" id="search-cancel-mobile">
                        取消
                    </a>
                </div><a class="menu-item" href="/posts/" title="">所有文章</a><a class="menu-item" href="/tags/" title="">标签</a><a class="menu-item" href="/categories/" title="">分类</a><a class="menu-item" href="https://github.com/dou-chi" title="" rel="noopener noreffer" target="_blank">github</a><a class="menu-item" href="https://gitee.com/dou-chi" title="" rel="noopener noreffer" target="_blank">gitee</a><a href="javascript:void(0);" class="menu-item theme-switch" title="切换主题">
                <i class="fas fa-adjust fa-fw"></i>
            </a></div>
    </div>
</header>
<div class="search-dropdown desktop">
    <div id="search-dropdown-desktop"></div>
</div>
<div class="search-dropdown mobile">
    <div id="search-dropdown-mobile"></div>
</div>
<main class="main">
                <div class="container"><div class="toc" id="toc-auto">
            <h2 class="toc-title">目录</h2>
            <div class="toc-content always-active" id="toc-content-auto"></div>
        </div><article class="page single"><h1 class="single-title animated flipInX">Docker容器可视化和主机可视化监控</h1><div class="post-meta">
            <div class="post-meta-line"><span class="post-author"><a href="/" title="Author" rel=" author" class="author"><i class="fas fa-user-circle fa-fw"></i>豆是不吃豆豉</a></span>&nbsp;<span class="post-category">收录于 <a href="/categories/docker/"><i class="far fa-folder fa-fw"></i>Docker</a>&nbsp;<a href="/categories/%E5%8F%AF%E8%A7%86%E5%8C%96%E7%9B%91%E6%8E%A7/"><i class="far fa-folder fa-fw"></i>可视化监控</a></span></div>
            <div class="post-meta-line"><i class="far fa-calendar-alt fa-fw"></i>&nbsp;<time datetime="2021-01-17">2021-01-17</time>&nbsp;<i class="fas fa-pencil-alt fa-fw"></i>&nbsp;约 1731 字&nbsp;
                <i class="far fa-clock fa-fw"></i>&nbsp;预计阅读 4 分钟&nbsp;</div>
        </div><div class="details toc" id="toc-static"  kept="">
                <div class="details-summary toc-title">
                    <span>目录</span>
                    <span><i class="details-icon fas fa-angle-right"></i></span>
                </div>
                <div class="details-content toc-content" id="toc-content-static"><nav id="TableOfContents">
  <ul>
    <li>
      <ul>
        <li><a href="#前言">前言</a></li>
        <li><a href="#cadvisor">cAdvisor</a></li>
        <li><a href="#prometheus">Prometheus</a></li>
        <li><a href="#grafana">Grafana</a></li>
        <li><a href="#node_exporter">node_exporter</a></li>
        <li><a href="#配置容器可视化监控">配置容器可视化监控</a></li>
        <li><a href="#配置主机可视化监控">配置主机可视化监控</a></li>
      </ul>
    </li>
  </ul>
</nav></div>
            </div><div class="content" id="content"><style>
    img {margin: 0 auto; display: block;}
</style>
<h2 id="前言">前言</h2>
<p>有时候我们想查看实时的<code>Docker</code>容器占用资源的情况和主机的资源占用，我们还需要<code>ssh</code>到主机，执行<code>docker stats</code>和<code>top</code>命令，数据不直观，无法显示一段时间来的数据变化。我们基于<code>cAdvisor</code>，<code>Grafana</code>，<code>Prometheus</code>，<code>node_exporter</code> 搭建一套可视化监控平台。主要用到的组件如下。</p>
<ul>
<li>Grafana: 数据可视化展示平台。</li>
<li>Prometheus：数据结构化存储。</li>
<li>cAdvisor：容器监控（实时数据，不存储数据）。</li>
<li>node_exporter：prometheus提供的监控主机的软件。</li>
</ul>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://s3.ax1x.com/2021/01/17/ssMvYd.png"
        data-srcset="https://s3.ax1x.com/2021/01/17/ssMvYd.png, https://s3.ax1x.com/2021/01/17/ssMvYd.png 1.5x, https://s3.ax1x.com/2021/01/17/ssMvYd.png 2x"
        data-sizes="auto"
        alt="https://s3.ax1x.com/2021/01/17/ssMvYd.png"
        title="docker-moniter-1" /></p>
<h2 id="cadvisor">cAdvisor</h2>
<p>拉取<code>cAdvisor</code>镜像并运行。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-shell" data-lang="shell"><span class="c1"># 拉取镜像</span>
docker pull google/cadvisor:v0.33.0

<span class="c1">#运行容器</span>
docker run -d <span class="se">\
</span><span class="se"></span>    -v /:/rootfs <span class="se">\
</span><span class="se"></span>    -v /var/run:/var/run <span class="se">\
</span><span class="se"></span>    -v /sys:/sys <span class="se">\
</span><span class="se"></span>	-v /var/lib/docker:/var/lib/docker <span class="se">\
</span><span class="se"></span>    -p 4000:8080 <span class="se">\
</span><span class="se"></span>	--privileged<span class="o">=</span><span class="nb">true</span> <span class="se">\
</span><span class="se"></span>	--name cadvisor google/cadvisor:v0.33.0 
</code></pre></td></tr></table>
</div>
</div><p>运行容器后，我们访问 4000 端口，即可看到容器的实时监控数据，但是它并不存储数据，所以我们需要使用其它组件来存储，如<code>influxDB</code>或者<code>prometheus</code>等。<code>metrics</code>的地址为<code>ip:端口/metrics</code>。</p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://s3.ax1x.com/2021/01/17/ss12ef.png"
        data-srcset="https://s3.ax1x.com/2021/01/17/ss12ef.png, https://s3.ax1x.com/2021/01/17/ss12ef.png 1.5x, https://s3.ax1x.com/2021/01/17/ss12ef.png 2x"
        data-sizes="auto"
        alt="https://s3.ax1x.com/2021/01/17/ss12ef.png"
        title="cadvisor" /></p>
<h2 id="prometheus">Prometheus</h2>
<p>拉取镜像并运行容器。<code>Prometheus</code>需要一个<code>yaml</code>格式的配置文件，我们在运行时指定挂载的配置文件。我们可以上官网找一份原始的配置文件，也可以运行一个临时的容器，使用<code>docker cp</code>从容器<code>/etc/prometheus/prometheus.yml</code>里面拷贝出来。命令如下:</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-shell" data-lang="shell"><span class="c1"># 拉取镜像</span>
docker pull prom/prometheus:v2.24.0

<span class="c1"># 运行临时容器，用于拷贝原始配置文件</span>
docker run --name prometheus-temp  prom/prometheus:v2.24.0
<span class="c1"># 拷贝文件到宿主机</span>
docker cp prometheus-temp:/etc/prometheus/prometheus.yml /usr/local/prometheus/config
<span class="c1"># 删除临时容器</span>
docker rm prometheus-temp

<span class="c1"># 修改prometheus.yml配置文件，添加cAdvisor端点,启动容器</span>
docker run -d -p 5500:9090 <span class="se">\
</span><span class="se"></span>	-v /usr/local/prometheus/config/prometheus.yml:/etc/prometheus/prometheus.yml <span class="se">\
</span><span class="se"></span>	--name prometheus <span class="se">\
</span><span class="se"></span>    prom/prometheus:v2.24.0
</code></pre></td></tr></table>
</div>
</div><p><code>prometheus.yml</code>配置</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span><span class="lnt">17
</span><span class="lnt">18
</span><span class="lnt">19
</span><span class="lnt">20
</span><span class="lnt">21
</span><span class="lnt">22
</span><span class="lnt">23
</span><span class="lnt">24
</span><span class="lnt">25
</span><span class="lnt">26
</span><span class="lnt">27
</span><span class="lnt">28
</span><span class="lnt">29
</span><span class="lnt">30
</span><span class="lnt">31
</span><span class="lnt">32
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-yaml" data-lang="yaml"><span class="c"># my global config</span><span class="w">
</span><span class="w"></span><span class="k">global</span><span class="p">:</span><span class="w">
</span><span class="w">  </span><span class="k">scrape_interval</span><span class="p">:</span><span class="w">     </span>15s<span class="w"> </span><span class="c"># Set the scrape interval to every 15 seconds. Default is every 1 minute.</span><span class="w">
</span><span class="w">  </span><span class="k">evaluation_interval</span><span class="p">:</span><span class="w"> </span>15s<span class="w"> </span><span class="c"># Evaluate rules every 15 seconds. The default is every 1 minute.</span><span class="w">
</span><span class="w">  </span><span class="c"># scrape_timeout is set to the global default (10s).</span><span class="w">
</span><span class="w">
</span><span class="w"></span><span class="c"># Alertmanager configuration</span><span class="w">
</span><span class="w"></span><span class="k">alerting</span><span class="p">:</span><span class="w">
</span><span class="w">  </span><span class="k">alertmanagers</span><span class="p">:</span><span class="w">
</span><span class="w">  </span>- <span class="k">static_configs</span><span class="p">:</span><span class="w">
</span><span class="w">    </span>- <span class="k">targets</span><span class="p">:</span><span class="w">
</span><span class="w">      </span><span class="c"># - alertmanager:9093</span><span class="w">
</span><span class="w">
</span><span class="w"></span><span class="c"># Load rules once and periodically evaluate them according to the global &#39;evaluation_interval&#39;.</span><span class="w">
</span><span class="w"></span><span class="k">rule_files</span><span class="p">:</span><span class="w">
</span><span class="w">  </span><span class="c"># - &#34;first_rules.yml&#34;</span><span class="w">
</span><span class="w">  </span><span class="c"># - &#34;second_rules.yml&#34;</span><span class="w">
</span><span class="w">
</span><span class="w"></span><span class="c"># A scrape configuration containing exactly one endpoint to scrape:</span><span class="w">
</span><span class="w"></span><span class="c"># Here it&#39;s Prometheus itself.</span><span class="w">
</span><span class="w"></span><span class="k">scrape_configs</span><span class="p">:</span><span class="w">
</span><span class="w">  </span><span class="c"># The job name is added as a label `job=&lt;job_name&gt;` to any timeseries scraped from this config.</span><span class="w">
</span><span class="w">  </span>- <span class="k">job_name</span><span class="p">:</span><span class="w"> </span><span class="s1">&#39;prometheus&#39;</span><span class="w">
</span><span class="w">
</span><span class="w">    </span><span class="c"># metrics_path defaults to &#39;/metrics&#39;</span><span class="w">
</span><span class="w">    </span><span class="c"># scheme defaults to &#39;http&#39;.</span><span class="w">
</span><span class="w">    </span><span class="k">static_configs</span><span class="p">:</span><span class="w">
</span><span class="w">    </span>- <span class="k">targets</span><span class="p">:</span><span class="w"> </span><span class="p">[</span><span class="s1">&#39;localhost:9090&#39;</span><span class="p">]</span><span class="w">
</span><span class="w"></span><span class="c">#============= 添加cAdvisor端点，地址为192.168.0.10:5500/metrics， metrics可省略</span><span class="w">
</span><span class="w">  </span>- <span class="k">job_name</span><span class="p">:</span><span class="w"> </span><span class="s1">&#39;docker监控&#39;</span><span class="w">
</span><span class="w">    </span><span class="k">static_configs</span><span class="p">:</span><span class="w">
</span><span class="w">    </span>- <span class="k">targets</span><span class="p">:</span><span class="w"> </span><span class="p">[</span><span class="s1">&#39;192.168.0.10:5500&#39;</span><span class="p">]</span><span class="w">
</span></code></pre></td></tr></table>
</div>
</div><p>启动成功后，我们访问宿主机<code>5500</code>端口，已经成功启动，等一会儿，输入<code>container</code>发现已经有数据了，cAdvisor数据以container开头，所以<code>prometheus</code>已经成功获取<code>cAdvisor</code>数据。</p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://s3.ax1x.com/2021/01/17/ss8w2d.png"
        data-srcset="https://s3.ax1x.com/2021/01/17/ss8w2d.png, https://s3.ax1x.com/2021/01/17/ss8w2d.png 1.5x, https://s3.ax1x.com/2021/01/17/ss8w2d.png 2x"
        data-sizes="auto"
        alt="https://s3.ax1x.com/2021/01/17/ss8w2d.png"
        title="prometheus" /></p>
<h2 id="grafana">Grafana</h2>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-shell" data-lang="shell">docker pull grafana/grafana:7.3.7

<span class="c1"># 运行</span>
docker run -d -p 5000:3000 --name grafana grafana/grafana:7.3.7
</code></pre></td></tr></table>
</div>
</div><p>浏览器打开5000端口，成功进入<code>grafana</code>输入，默认用户名密码都为<code>admin</code>修改密码后，进入主界面。</p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://s3.ax1x.com/2021/01/17/ssGlFS.png"
        data-srcset="https://s3.ax1x.com/2021/01/17/ssGlFS.png, https://s3.ax1x.com/2021/01/17/ssGlFS.png 1.5x, https://s3.ax1x.com/2021/01/17/ssGlFS.png 2x"
        data-sizes="auto"
        alt="https://s3.ax1x.com/2021/01/17/ssGlFS.png"
        title="grafana" /></p>
<h2 id="node_exporter">node_exporter</h2>
<p><code>node_exporter</code>是<code>prometheus</code>提供的开源的主机监控软件，也可以使用<code>docker</code>运行，但官方并<code>不推荐使用docker</code>运行，所以我们直接安装在宿主机上。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span><span class="lnt">17
</span><span class="lnt">18
</span><span class="lnt">19
</span><span class="lnt">20
</span><span class="lnt">21
</span><span class="lnt">22
</span><span class="lnt">23
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-shell" data-lang="shell"><span class="c1"># 从github获取，我是放在 /usr/local/node_exporter</span>
wget https://github.com/prometheus/node_exporter/releases/download/v1.0.1/node_exporter-1.0.1.linux-amd64.tar.gz
<span class="c1"># 解压</span>
tar zxf node_exporter-1.0.1.linux-amd64.tar.gz
<span class="c1"># 创建启动脚本</span>
cat <span class="s">&lt;&lt;EOF &gt; /usr/lib/systemd/system/node_exporter.service
</span><span class="s">[Unit]
</span><span class="s">Description=https://github.com/prometheus
</span><span class="s">
</span><span class="s">[Service]
</span><span class="s">Restart=on-failure
</span><span class="s">ExecStart=/usr/local/node_exporter/node_exporter
</span><span class="s">
</span><span class="s">[Install]
</span><span class="s">WanteBy=muti-user.target
</span><span class="s">
</span><span class="s">EOF</span>


<span class="c1"># 开机自启</span>
systemctl <span class="nb">enable</span> node_exporter
<span class="c1"># 启动</span>
systemctl start node_exporter
</code></pre></td></tr></table>
</div>
</div><p><code>node_exporter</code>默认的端口是<code>9100</code>，我们访问浏览器<code>ip:9100/metrics</code>发现已经有数据了，启动成功。我们需要配置<code>Prometheus</code>也获取<code>node_exporter</code>数据，我们在<code>prometheus.yml</code>中增加端点，重启<code>Prometheus</code>，访问<code>Prometheus</code>地址，使用<code>node</code>搜索，有提示，说明已经成功监控<code>node_exporter</code></p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-shell" data-lang="shell">  - job_name: <span class="s1">&#39;主机监控&#39;</span>
    static_configs:
    - targets: <span class="o">[</span><span class="s1">&#39;192.168.0.10:9100&#39;</span><span class="o">]</span>
</code></pre></td></tr></table>
</div>
</div><p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://s3.ax1x.com/2021/01/17/ssYEDI.png"
        data-srcset="https://s3.ax1x.com/2021/01/17/ssYEDI.png, https://s3.ax1x.com/2021/01/17/ssYEDI.png 1.5x, https://s3.ax1x.com/2021/01/17/ssYEDI.png 2x"
        data-sizes="auto"
        alt="https://s3.ax1x.com/2021/01/17/ssYEDI.png"
        title="node_exporter" /></p>
<h2 id="配置容器可视化监控">配置容器可视化监控</h2>
<p>增加数据源，添加<code>Prometheus</code>数据源,点击<code>save&amp;test</code>成功访问。</p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://s3.ax1x.com/2021/01/17/ssYM8g.png"
        data-srcset="https://s3.ax1x.com/2021/01/17/ssYM8g.png, https://s3.ax1x.com/2021/01/17/ssYM8g.png 1.5x, https://s3.ax1x.com/2021/01/17/ssYM8g.png 2x"
        data-sizes="auto"
        alt="https://s3.ax1x.com/2021/01/17/ssYM8g.png"
        title="grafana" /></p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://s3.ax1x.com/2021/01/17/ssYN5T.png"
        data-srcset="https://s3.ax1x.com/2021/01/17/ssYN5T.png, https://s3.ax1x.com/2021/01/17/ssYN5T.png 1.5x, https://s3.ax1x.com/2021/01/17/ssYN5T.png 2x"
        data-sizes="auto"
        alt="https://s3.ax1x.com/2021/01/17/ssYN5T.png"
        title="grafana" /></p>
<p>我们可以上<code>grafana</code>官方寻找合适的模板或者自己自定义添加图表，这里我们选择导入<code>grafana</code>容器监控的模板id为<code>193</code>，修改名称为<code>docker监控</code>,导入，进入页面，已经成功监控容器了。</p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://s3.ax1x.com/2021/01/17/ssYRPO.png"
        data-srcset="https://s3.ax1x.com/2021/01/17/ssYRPO.png, https://s3.ax1x.com/2021/01/17/ssYRPO.png 1.5x, https://s3.ax1x.com/2021/01/17/ssYRPO.png 2x"
        data-sizes="auto"
        alt="https://s3.ax1x.com/2021/01/17/ssYRPO.png"
        title="template" /></p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://s3.ax1x.com/2021/01/17/ssYbIf.png"
        data-srcset="https://s3.ax1x.com/2021/01/17/ssYbIf.png, https://s3.ax1x.com/2021/01/17/ssYbIf.png 1.5x, https://s3.ax1x.com/2021/01/17/ssYbIf.png 2x"
        data-sizes="auto"
        alt="https://s3.ax1x.com/2021/01/17/ssYbIf.png"
        title="docker monitor" /></p>
<h2 id="配置主机可视化监控">配置主机可视化监控</h2>
<p>我们同样选择导入一个新的模板，id为<code>9276</code>，改名为<code>主机监控</code>,保存后进入页面，已经成功监控主机状态。</p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://s3.ax1x.com/2021/01/17/sstlFK.png"
        data-srcset="https://s3.ax1x.com/2021/01/17/sstlFK.png, https://s3.ax1x.com/2021/01/17/sstlFK.png 1.5x, https://s3.ax1x.com/2021/01/17/sstlFK.png 2x"
        data-sizes="auto"
        alt="https://s3.ax1x.com/2021/01/17/sstlFK.png"
        title="node_exporter" /></p>
<p>如果无法读取网络数据，有可能是网卡信息错误，我们手动修改一下网卡信息即可。</p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://s3.ax1x.com/2021/01/17/sst5fU.png"
        data-srcset="https://s3.ax1x.com/2021/01/17/sst5fU.png, https://s3.ax1x.com/2021/01/17/sst5fU.png 1.5x, https://s3.ax1x.com/2021/01/17/sst5fU.png 2x"
        data-sizes="auto"
        alt="https://s3.ax1x.com/2021/01/17/sst5fU.png"
        title="network" /></p>
<p>至此，我们旧成功的搭建了主机和容器的可视化监控。</p>
</div><div class="post-footer" id="post-footer">
    <div class="post-info">
        <div class="post-info-line">
            <div class="post-info-mod">
                <span>更新于 2021-01-17</span>
            </div>
            <div class="post-info-license"></div>
        </div>
        <div class="post-info-line">
            <div class="post-info-md"><span>
                            <a class="link-to-markdown" href="/docker-monitor/index.md" target="_blank">阅读原始文档</a>
                        </span></div>
            <div class="post-info-share">
                <span><a href="javascript:void(0);" title="分享到 Twitter" data-sharer="twitter" data-url="https://dou-chi.gitee.io/docker-monitor/" data-title="Docker容器可视化和主机可视化监控" data-hashtags="docker,cAdvisor,Grafana,Prometheus,node_exporter"><i class="fab fa-twitter fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Facebook" data-sharer="facebook" data-url="https://dou-chi.gitee.io/docker-monitor/" data-hashtag="docker"><i class="fab fa-facebook-square fa-fw"></i></a><a href="javascript:void(0);" title="分享到 WhatsApp" data-sharer="whatsapp" data-url="https://dou-chi.gitee.io/docker-monitor/" data-title="Docker容器可视化和主机可视化监控" data-web><i class="fab fa-whatsapp fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Line" data-sharer="line" data-url="https://dou-chi.gitee.io/docker-monitor/" data-title="Docker容器可视化和主机可视化监控"><i data-svg-src="/lib/simple-icons/icons/line.min.svg"></i></a><a href="javascript:void(0);" title="分享到 微博" data-sharer="weibo" data-url="https://dou-chi.gitee.io/docker-monitor/" data-title="Docker容器可视化和主机可视化监控"><i class="fab fa-weibo fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Myspace" data-sharer="myspace" data-url="https://dou-chi.gitee.io/docker-monitor/" data-title="Docker容器可视化和主机可视化监控" data-description="Docker容器可视化和主机可视化监控"><i data-svg-src="/lib/simple-icons/icons/myspace.min.svg"></i></a><a href="javascript:void(0);" title="分享到 Blogger" data-sharer="blogger" data-url="https://dou-chi.gitee.io/docker-monitor/" data-title="Docker容器可视化和主机可视化监控" data-description="Docker容器可视化和主机可视化监控"><i class="fab fa-blogger fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Evernote" data-sharer="evernote" data-url="https://dou-chi.gitee.io/docker-monitor/" data-title="Docker容器可视化和主机可视化监控"><i class="fab fa-evernote fa-fw"></i></a></span>
            </div>
        </div>
    </div>

    <div class="post-info-more">
        <section class="post-tags"><i class="fas fa-tags fa-fw"></i>&nbsp;<a href="/tags/docker/">docker</a>,&nbsp;<a href="/tags/cadvisor/">cAdvisor</a>,&nbsp;<a href="/tags/grafana/">Grafana</a>,&nbsp;<a href="/tags/prometheus/">Prometheus</a>,&nbsp;<a href="/tags/node_exporter/">node_exporter</a></section>
        <section>
            <span><a href="javascript:void(0);" onclick="window.history.back();">返回</a></span>&nbsp;|&nbsp;<span><a href="/">主页</a></span>
        </section>
    </div>

    <div class="post-nav"><a href="/jenkins-auto-test/" class="prev" rel="prev" title="Jenkins Docker 用与测试环境的自动打包Vue项目和SpringBoot项目"><i class="fas fa-angle-left fa-fw"></i>Jenkins Docker 用与测试环境的自动打包Vue项目和SpringBoot项目</a>
            <a href="/act-img-fix/" class="next" rel="next" title="修复Activiti5.22.0部署流程，流程图片流程连线名称不显示的问题">修复Activiti5.22.0部署流程，流程图片流程连线名称不显示的问题<i class="fas fa-angle-right fa-fw"></i></a></div>
</div>
<div id="comments"></div></article></div>
            </main><footer class="footer">
        <div class="footer-container"><div class="footer-line">由 <a href="https://gohugo.io/" target="_blank" rel="noopener noreffer" title="Hugo 0.74.3">Hugo</a> 强力驱动 | 主题 - <a href="https://github.com/dillonzq/LoveIt" target="_blank" rel="noopener noreffer" title="LoveIt 0.2.10"><i class="far fa-kiss-wink-heart fa-fw"></i> LoveIt</a>
                </div><div class="footer-line"><i class="far fa-copyright fa-fw"></i><span itemprop="copyrightYear">2019 - 2021</span><span class="author" itemprop="copyrightHolder">&nbsp;<a href="/" target="_blank">豆是不吃豆豉</a></span></div>
        </div>
    </footer></div>

        <div id="fixed-buttons"><a href="#" id="back-to-top" class="fixed-button" title="回到顶部">
                <i class="fas fa-arrow-up fa-fw"></i>
            </a><a href="#" id="view-comments" class="fixed-button" title="查看评论">
                <i class="fas fa-comment fa-fw"></i>
            </a>
        </div><link rel="stylesheet" href="/lib/katex/katex.min.css"><link rel="stylesheet" href="/lib/katex/copy-tex.min.css"><link rel="stylesheet" href="/lib/cookieconsent/cookieconsent.min.css"><script type="text/javascript" src="/lib/smooth-scroll/smooth-scroll.min.js"></script><script type="text/javascript" src="/lib/autocomplete/autocomplete.min.js"></script><script type="text/javascript" src="/lib/lunr/lunr.min.js"></script><script type="text/javascript" src="/lib/lunr/lunr.stemmer.support.min.js"></script><script type="text/javascript" src="/lib/lunr/lunr.zh.min.js"></script><script type="text/javascript" src="/lib/lazysizes/lazysizes.min.js"></script><script type="text/javascript" src="/lib/clipboard/clipboard.min.js"></script><script type="text/javascript" src="/lib/sharer/sharer.min.js"></script><script type="text/javascript" src="/lib/katex/katex.min.js"></script><script type="text/javascript" src="/lib/katex/auto-render.min.js"></script><script type="text/javascript" src="/lib/katex/copy-tex.min.js"></script><script type="text/javascript" src="/lib/katex/mhchem.min.js"></script><script type="text/javascript" src="/lib/cookieconsent/cookieconsent.min.js"></script><script type="text/javascript">window.config={"code":{"copyTitle":"复制到剪贴板","maxShownLines":100},"comment":{},"cookieconsent":{"content":{"dismiss":"同意","link":"了解更多","message":"本网站使用 Cookies 来改善您的浏览体验."},"enable":true,"palette":{"button":{"background":"#f0f0f0"},"popup":{"background":"#1aa3ff"}},"theme":"edgeless"},"math":{"delimiters":[{"display":true,"left":"$$","right":"$$"},{"display":true,"left":"\\[","right":"\\]"},{"display":false,"left":"$","right":"$"},{"display":false,"left":"\\(","right":"\\)"}],"strict":false},"search":{"highlightTag":"em","lunrIndexURL":"/index.json","lunrLanguageCode":"zh","lunrSegmentitURL":"/lib/lunr/lunr.segmentit.js","maxResultLength":10,"noResultsFound":"没有找到结果","snippetLength":50,"type":"lunr"}};</script><script type="text/javascript" src="/js/theme.min.js"></script></body>
</html>
